<template>
	<view>
		<uni-nav-bar left-icon="back" @click-left="back" @click-right="save()" right-text="保存" title="工作单位信息"></uni-nav-bar>
		<view class="list">
			<view class="list-item">
				<text>公司名称</text>
				<view class="input">
					<input class="inputText" type="text" data-name="name" @input="input" :value="jobData.name" placeholder="请填写公司名称" placeholder-class="placeholder" />
				</view>
			</view>
			<view class="list-item">
				<text>座机号码</text>
				<view class="input">
					<input class="inputText" type="text" data-name="phone" @input="input" :value="jobData.phone" placeholder="请填写座机号码" placeholder-class="placeholder" />
				</view>
			</view>
			<view class="list-item">
				<text>详细地址</text>
				<view class="input">
					<input class="inputText" type="text" data-name="address" @input="input" :value="jobData.address" placeholder="请填写详细地址" placeholder-class="placeholder" />
				</view>
			</view>
			<view class="list-item">
				<text>同事</text>
				<view class="input">
					<input
						class="inputText"
						type="text"
						data-name="worker_one"
						@input="input"
						:value="jobData.worker_one"
						placeholder="请填写同事姓名"
						placeholder-class="placeholder"
					/>
				</view>
			</view>
			<view class="list-item">
				<text>同事电话</text>
				<view class="input">
					<input
						class="inputText"
						type="text"
						data-name="phone_one"
						@input="input"
						:value="jobData.phone_one"
						placeholder="请填写同事电话"
						placeholder-class="placeholder"
					/>
				</view>
			</view>
		</view>
		<view class="block"></view>
		<view class="list">
			<view class="list-item">
				<text>同事</text>
				<view class="input">
					<input
						class="inputText"
						type="text"
						data-name="worker_two"
						@input="input"
						:value="jobData.worker_two"
						placeholder="请填写同事姓名"
						placeholder-class="placeholder"
					/>
				</view>
			</view>
			<view class="list-item">
				<text>同事电话</text>
				<view class="input">
					<input
						class="inputText"
						type="text"
						data-name="phone_two"
						@input="input"
						:value="jobData.phone_two"
						placeholder="请填写同事电话"
						placeholder-class="placeholder"
					/>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
import uniIcons from '@/components/uni-icons/uni-icons.vue';
export default {
	components: { uniNavBar, uniIcons },
	data() {
		return {
			jobData: {
				name: '',
				phone: '',
				address: '',
				worker_one: '',
				phone_one: '',
				worker_two: '',
				phone_two: ''
			}
		};
	},
	onLoad() {
		this.getData();
	},
	methods: {
		async getData() {
			let res = await this.$request.get('/setting/setMemberWorker', {});
			let data = res.data.data.list;
			if (data) {
				let { name, phone, address, worker_one, phone_one, worker_two, phone_two } = data;
				this.jobData = {
					name,
					phone,
					address,
					worker_one,
					phone_one,
					worker_two,
					phone_two
				};
			}
		},
		input(e) {
			let name = e.target.dataset.name;
			let value = e.detail.value;
			this.jobData[name] = value;
		},
		back() {
			uni.navigateBack({
				delta: 1
			});
		},
		async save() {
			let jobData = this.jobData;
			for (let key in jobData) {
				if (!jobData[key]) {
					uni.showToast({
						title: '请将表单填写完整',
						duration: 2000
					});
					console.log(key);
					return false;
				}
			}
			let res = await this.$request.post('/setting/setMemberWorker', {
				data: {
					...jobData
				}
			});
			if (res.data.code == 10000) {
				uni.showToast({
					title: '保存成功',
					duration: 2000
				});
				setTimeout(() => {
					uni.navigateBack({
						delta: 1
					});
				}, 2000);
			} else {
				uni.showToast({
					title: '保存失败',
					duration: 2000
				});
			}
		}
	}
};
</script>

<style lang="scss">
.list {
	width: 100%;
	box-sizing: border-box;
	padding-left: 30upx;
	.list-item {
		width: 100%;
		height: 110upx;
		border-bottom: 2upx solid #e7e7e7;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-sizing: border-box;
		padding-right: 20upx;
		font-size: $uni-font-size-base;
		color: #333333;
		.input {
			width: 500upx;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			.inputText {
				color: #333333;
				font-size: $uni-font-size-base;
				width: 100%;
				text-align: right;
				box-sizing: border-box;
			}
		}
	}
}
.placeholder {
	color: #d7d7d7;
}
.block {
	width: 100%;
	height: 20upx;
	background-color: #f5f6f7;
}
</style>
